<!-- 授权中转页面 -->
<template>
    <div>
    </div>
</template>

<script>
import { ref, reactive, getCurrentInstance } from 'vue';
import storage from 'store';
import { ACCESS_TOKEN , BRANDID , ACCESS_TOKEN_BRAND } from '@/utils/types';
export default {
    setup() {
        const { proxy } = getCurrentInstance();
        var type = 0;
        if(!proxy.getHashParam('code')){
            // window.location.href = 'https://aipin.minghublock.com/aipin/aipinTest/getcode.html'
            var list = decodeURIComponent(proxy.getHashParam('sign')).split(',')
            console.log(list,'list')
            // localStorage.setItem('signKey',list[0]),
            // localStorage.setItem('brandId',list[1]),
            // localStorage.setItem('merchantNo',list[2]),
            storage.set(BRANDID,list[1])
            storage.set('signKey',list[0])
            storage.set('merchantNo',list[2])
            storage.set('appId',list[3])
            if(list.length > 5){
                type = list[5];
            }
        }else{
            let code = proxy.getHashParam('code')
            // localStorage.setItem('code',code)
            var list = decodeURIComponent(proxy.getHashParam('state')).split(',')
            // localStorage.setItem('signKey',list[0]),
            // localStorage.setItem('brandId',list[1]),
            // localStorage.setItem('merchantNo',list[2]),
            storage.set('code',code)
            storage.set(BRANDID,list[1])
            storage.set('signKey',list[0])
            storage.set('merchantNo',list[2])
            storage.set('appId',list[3])
            if(list.length > 5){
                type = list[5];
            }
        }

        // 获取配置的系统token
        // 获取系统的token
        const brandId = storage.get(BRANDID)
        function getToken(brandId,isBrand){
            return new Promise((resolve,reject)=>{
                proxy.$http.brandApi.getToken(brandId)
                .then(res=>{
                    if(res.success){
                        if(isBrand == '1'){
                            storage.set(ACCESS_TOKEN,res[ACCESS_TOKEN], res.expires_in)
                            
                        }else{
                            storage.set(ACCESS_TOKEN_BRAND,res[ACCESS_TOKEN], res.expires_in)
                        }
                        console.log('111222333')
                        resolve()
                    }
                })
            })
        }
        const allPromis = async() =>{
            await getToken(1,0)
            await getToken(brandId,'1')
            // type ,1：话费慢充，2：话费快充，3：电费慢充，4：电费快充
            console.log(type,'type')
            switch(type){
                case '1':
                    proxy.$router.push({name: 'telephoneCharge',params: {'edition': '1'}})
                    break;
                case '2':
                    proxy.$router.push({name: 'telephoneCharge',params: {'edition': '2'}})
                    break;
                case '3':
                    proxy.$router.push({name: 'electricityCharge',params: {'edition': '2'}})
                    break;
                case '4':
                    proxy.$router.push({name: 'electricityCharge',params: {'edition': '1'}})
                    break;
                case '5':
                    proxy.$router.push({name: 'tiktokCurrency',params: {'edition': '2'}})
                    break;
                case '6':
                    proxy.$router.push({name: 'cardCoupon'})
                    break;
                default:
                    proxy.$router.push({name: 'home'});
                    break;
            }
            
        }
        allPromis();
        return {
        }
    }
}

</script>
<style scoped>

</style>